package com.my.serviceimpl;

import com.my.bean.MoenyDetailed;
import com.my.bean.ResultPage;
import com.my.bean.VoPage;
import com.my.bean.pojoVo.MoenyInfoPojo;
import com.my.bean.pojoVo.MoneyMoth;
import com.my.bean.pojoVo.moneyPojo;
import com.my.mapper.MoenyDetailedMapper;
import com.my.service.MoenyDetailedService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 收费明细表   每个订单对应多个和明细表 服务实现类
 * </p>
 *
 * @author 张子艺
 * @since 2018-08-25
 */
@Service
public class MoenyDetailedServiceImpl extends ServiceImpl<MoenyDetailedMapper, MoenyDetailed> implements MoenyDetailedService {


    @Override
    public ResultPage<moneyPojo> selectMyPage(VoPage voPage,long areaid,boolean admin) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("page", (voPage.getPage() - 1)*voPage.getLimit());
        paramMap.put("limit", voPage.getLimit());
        List<moneyPojo> list = baseMapper.findMoenySum(paramMap,areaid,admin);
        Integer count = baseMapper.findMoenySumCount(paramMap,areaid,admin);
        ResultPage<moneyPojo>resultPage=new ResultPage<>();
        resultPage.setCode(0);
        resultPage.setCount(count);
        resultPage.setMsg("成功");
        resultPage.setData(list);
        return resultPage;
    }

    @Override
    public List<MoenyInfoPojo> findMoenySumCountByHomeId(Long homeId,boolean admin) {
        return baseMapper.findMoenySumCountByHomeId(homeId,admin);
    }

    @Override
    public ResultPage<MoneyMoth> findMothData(VoPage voPage) {
        //多条sql结果拼接为一个集合
        List<MoneyMoth> MothSumSingular=baseMapper.findMothSumSingular();
        List<MoneyMoth> MothMea=baseMapper.findMothMea();
        List<MoneyMoth> MothEW=baseMapper.findMothEW();
        for (int i = 0; i < MothSumSingular.size(); i++) {
            for (int j = 0; j < MothMea.size(); j++) {
                for (int k = 0; k < MothEW.size(); k++) {
                    if(MothSumSingular.get(i).getMoth().equals(MothMea.get(j).getMoth())){
                        MothSumSingular.get(i).setMeaPrice(MothMea.get(j).getMeaPrice());
                    }
                    if (MothSumSingular.get(i).getMoth().equals(MothEW.get(k).getMoth())){
                        MothSumSingular.get(i).setAdded(MothEW.get(k).getAdded());
                    }
                }
            }
        }
        ResultPage<MoneyMoth>resultPage=new ResultPage<>();
        resultPage.setCode(0);
        resultPage.setCount(MothSumSingular.size());
        resultPage.setMsg("成功");
        if(MothSumSingular.size()<voPage.getLimit()){
            resultPage.setData(MothSumSingular);
        }else {
            resultPage.setData(MothSumSingular.subList(voPage.getPage()-1,voPage.getLimit()-1));
        }

        return resultPage;
    }
}
